# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=numba
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.56.4
pkgrel=1
pkgdesc='NumPy aware dynamic Python compiler using LLVM (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://numba.pydata.org/"
license=('BSD')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python-llvmlite>=0.37"
  "${MINGW_PACKAGE_PREFIX}-python-numpy>=1.17"
  $([[ ${MINGW_PACKAGE_PREFIX} != *-clang-*86* ]] || echo "${MINGW_PACKAGE_PREFIX}-openmp")
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools" "${MINGW_PACKAGE_PREFIX}-cython" "${MINGW_PACKAGE_PREFIX}-cc")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-scipy>=1.0.0")
options=('!emptydirs')
source=(numba-$pkgver.tar.gz::"https://github.com/numba/numba/archive/$pkgver.tar.gz"
        "001-Fix-checking-Windows-platform-with-_WIN32-instead-of-_MSC_VER.patch"::"https://github.com/numba/numba/commit/ee52198b.patch")
sha256sums=('ab96b731fb9dee12b404b42b7c1fb82c119352648906a80526afa73658895b73'
            '183c4bf59aae92215f680d68b338515a58ef9b93d25e1857140bf2022235406b')

prepare() {
  cd "$srcdir/${_realname}-${pkgver}"
	patch -p1 -i "${srcdir}/001-Fix-checking-Windows-platform-with-_WIN32-instead-of-_MSC_VER.patch"

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  NUMBA_DISABLE_TBB=1 \
    ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  local _PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/numba"
  sed -s "s|${_PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/pycc"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
